package com.hotel.controller;

import com.hotel.common.AjaxResult;
import com.hotel.domain.service.GuestsService;
import com.hotel.pojo.Guests;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/guests")
public class GuestsController {

    @Autowired
    private GuestsService guestsService;

    /**
     * 分页查询顾客列表
     * @param guests 顾客对象
     * @param page 页码
     * @param perPage 每页的条数
     * @return AjaxResult
     */
    @GetMapping("/{page}/{perPage}")
    @ResponseBody
    public AjaxResult getGuestsList(Guests guests, @PathVariable("page") int page, @PathVariable("perPage") int perPage){
        return AjaxResult.queryAjax(guestsService.getGuestsList(guests, page, perPage));
    }

    /**
     * 增加顾客
     * @param guests 顾客对象
     * @return AjaxResult
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addGuests(@RequestBody Guests guests){
        return AjaxResult.updateAjax(guestsService.addGuests(guests));
    }

    /**
     * 更新顾客信息
     * @param guests 顾客对象
     * @return AjaxResult
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateGuests(@RequestBody Guests guests){
        return AjaxResult.updateAjax(guestsService.updateGuests(guests));
    }

    /**
     * 逻辑删除
     * @param guestId 顾客ID
     * @return AjaxResult
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult deleteGuests(@RequestBody int guestId){
        Guests guests = new Guests();
        guests.setGuestDel(1);
        guests.setGuestId(guestId);
        return AjaxResult.updateAjax(guestsService.updateGuests(guests));
    }

    /**
     * 升级为vip
     * @param guestId 顾客ID
     * @return AjaxResult
     */
    @PostMapping("/upToVip")
    @ResponseBody
    public AjaxResult upToVip(@RequestBody int guestId){
        return AjaxResult.updateAjax(guestsService.upToVip(guestId));
    }

}
